package com.atguigu.common.config;

import com.atguigu.common.minio.MinioProperties;
import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ClassName: MinioConfiguration
 * Package: com.atguigu.common.config
 * Description: Minio配置类
 *
 * @Author 梅超凡
 * @Create 2024/11/15 9:42
 * @Version 1.0
 */
@Configuration
@EnableConfigurationProperties(MinioProperties.class)
public class MinioConfiguration {

    @Autowired
    private MinioProperties properties;

    /**
     * @Author 梅超凡
     * @Date 2024/11/15~9:44
     * @Description 创建MinIO客户端
    */
    @Bean
    public MinioClient minioClient() {
        // 创建MinIO客户端
        return MinioClient
                .builder()
                // 设置MinIO服务端地址
                .endpoint(properties.getEndpoint())
                // 设置访问凭证
                .credentials(properties.getAccessKey(),
                             properties.getSecretKey())
                .build();
    }
}
